/** @file check_box.cpp
 */
#include "check_box.h"



CheckBox::CheckBox(HWND parent) : Widget(parent)
{
    name ="CheckBox";
    activable =1;
    state =0;

    rect.x1 =rect.x0 + 10;
    rect.y1 =rect.y0 + 10;
}


CheckBox::~CheckBox()
{
}

void CheckBox::draw(Rect *r)
{
    //blanc this erea
    pDC->fillRect(rect.x0, rect.y0, rect.x1, rect.y1, 0);

   if(isActive())
   {
        //draw a rectangle
        pDC->drawRect(rect.x0, rect.y0, rect.x1, rect.y1, 0x0F);
    }
        //draw a solid rectangle
    if(state)
    {
        pDC->fillRect(rect.x0+2, rect.y0+2, rect.x1-2, rect.y1-2, 0x0F);
    }
    else
    {
        pDC->drawRect(rect.x0+2, rect.y0+2, rect.x1-2, rect.y1-2, 0x0F);
    }

    pDC->dirty(max(r->x0,rect.x0), max(r->y0,rect.y0), min(r->x1,rect.x1), min(r->y1,rect.y1));

    Widget::draw(r);
}

void CheckBox::setChecked(bool state)
{
    this->state =state;
}

bool CheckBox::getCheck()
{
    return state;
}

int CheckBox::eventHandler(HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam)
{
    switch(iMsg)
    {
        case MSG_KEY_DOWN:
            switch(wParam)
            {
                case KEY_ENTER:
                state ^=1;
                signal[SIGNAL_CHECKBOX_CHANGED].emitSignal();
                draw(&rect);
                break;
            }
        break;
    }

    return Widget::eventHandler(hWnd, iMsg, wParam, lParam);
}

